#include <bits/stdc++.h>
using namespace std;
int t,n,a[200005],c[200005],maxn,lasta,lastb;
void dfs(int step){
    if (step==n+1){
        int score=0;
        lasta=-1,lastb=-1;
        for (int i=1;i<=n;i++){
            if (c[i]==1){
                if (a[i]==lasta) score+=lasta;
                lasta=a[i];
            }
            else{
                if (a[i]==lastb) score+=lastb;
                lastb=a[i];
            }
            //cout<<score<<' ';
        }
        maxn=max(maxn,score);
        return;
    }
    c[step]=1;
    dfs(step+1);
    c[step]=2;
    dfs(step+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while (t--){
        cin>>n;
        maxn=0;
        for (int i=1;i<=n;i++) cin>>a[i];
        lasta=-1,lastb=-1;
        dfs(1);
        cout<<maxn<<"\n";
    }
    return 0;
}
